/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.format.annotation.DateTimeFormat;

/**
 *
 * @author Administrador					
 */											
@Entity
@Table(name = "userprovider")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Userprovider.findAll", query = "SELECT u FROM Userprovider u"),
    @NamedQuery(name = "Userprovider.findByProviderId", query = "SELECT u FROM Userprovider u WHERE u.userproviderPK.providerId = :providerId"),
    @NamedQuery(name = "Userprovider.findByProviderIdByUserProviderId", query = "SELECT u FROM Userprovider u WHERE u.userproviderPK.providerId = :providerId AND u.userproviderPK.userProviderId = :userProviderId"),
    @NamedQuery(name = "Userprovider.findByProviderIdByActive", query = "SELECT u FROM Userprovider u WHERE u.userproviderPK.providerId = :providerId AND u.active = :active"),
    @NamedQuery(name = "Userprovider.findByUserProviderId", query = "SELECT u FROM Userprovider u WHERE u.userproviderPK.userProviderId = :userProviderId"),
    @NamedQuery(name = "Userprovider.findByUserProviderIdMax", query = "SELECT max(u.userproviderPK.userProviderId) FROM Userprovider u"),
    @NamedQuery(name = "Userprovider.findByUserProviderIdByActive", query = "SELECT u FROM Userprovider u WHERE u.userproviderPK.userProviderId = :userProviderId AND u.active = :active"),
    @NamedQuery(name = "Userprovider.findByName", query = "SELECT u FROM Userprovider u WHERE u.name = :name"),
    @NamedQuery(name = "Userprovider.findByLastName", query = "SELECT u FROM Userprovider u WHERE u.lastName = :lastName"),
    @NamedQuery(name = "Userprovider.findByLastName2", query = "SELECT u FROM Userprovider u WHERE u.lastName2 = :lastName2"),
    @NamedQuery(name = "Userprovider.findByCi", query = "SELECT u FROM Userprovider u WHERE u.ci = :ci"),
    @NamedQuery(name = "Userprovider.findByGenero", query = "SELECT u FROM Userprovider u WHERE u.genero = :genero"),
    @NamedQuery(name = "Userprovider.findByCellphone", query = "SELECT u FROM Userprovider u WHERE u.cellphone = :cellphone"),
    @NamedQuery(name = "Userprovider.findByPhone", query = "SELECT u FROM Userprovider u WHERE u.phone = :phone"),
    @NamedQuery(name = "Userprovider.findByEmail", query = "SELECT u FROM Userprovider u WHERE u.email = :email"),
    @NamedQuery(name = "Userprovider.findByEmail2", query = "SELECT u FROM Userprovider u WHERE u.email2 = :email2"),
    @NamedQuery(name = "Userprovider.findByAddress", query = "SELECT u FROM Userprovider u WHERE u.address = :address"),
    @NamedQuery(name = "Userprovider.findByBirthdate", query = "SELECT u FROM Userprovider u WHERE u.birthdate = :birthdate"),
    @NamedQuery(name = "Userprovider.findByPicture", query = "SELECT u FROM Userprovider u WHERE u.picture = :picture"),
    @NamedQuery(name = "Userprovider.findByLogin", query = "SELECT u FROM Userprovider u WHERE u.login = :login"),
    @NamedQuery(name = "Userprovider.findByPassword", query = "SELECT u FROM Userprovider u WHERE u.password = :password"),
    @NamedQuery(name = "Userprovider.findByRolProviderIdByActive", query = "SELECT u FROM Userprovider u WHERE u.rolProviderId.rolProviderId = :rolProviderId AND u.active = :active order by u.name"),
    /*
     @NamedQuery(name = "Locality.deleteByLocalityIdByRegionId", query = "DELETE FROM Locality l WHERE l.localityPK.regionId = :regionId AND l.localityPK.localityId = :localityId"), 
     */
    @NamedQuery(name = "Userprovider.deleteByProviderIdByUserProviderId", query = "DELETE FROM Userprovider u WHERE u.userproviderPK.providerId = :providerId AND u.userproviderPK.userProviderId = :userProviderId"),
    @NamedQuery(name = "Userprovider.findByRolProviderIdByProviderIdByActive", query = "SELECT u FROM Userprovider u WHERE u.rolProviderId.rolProviderId = :rolProviderId AND u.userproviderPK.providerId = :providerId AND u.active = :active order by u.name"),
    @NamedQuery(name = "Userprovider.findByActive", query = "SELECT u FROM Userprovider u WHERE u.active = :active")})
public class Userprovider implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserproviderPK userproviderPK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "lastName")
    private String lastName;
    @Column(name = "lastName2")
    private String lastName2;
    @Basic(optional = false)
    @Column(name = "ci")
    private String ci;
    @Basic(optional = false)
    @Column(name = "genero")
    private char genero;
    @Column(name = "cellphone")
    private String cellphone;
    @Basic(optional = false)
    @Column(name = "phone")
    private String phone;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;
    @Column(name = "email2")
    private String email2;
    @Column(name = "address")
    private String address;				
    @Column(name = "birthdate")					   
    @Temporal(TemporalType.DATE)
    private Date birthdate;    		// @DateTimeFormat(pattern = "dd/MM/yyyy")
    @Column(name = "picture")
    private String picture;
    @Basic(optional = false)
    @Column(name = "login")
    private String login;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @Column(name = "active")
    private boolean active;
    @OneToMany(mappedBy = "userprovider")
    private Collection<Package> packageCollection;
    @JoinColumn(name = "rolProviderId", referencedColumnName = "rolProviderId")
    @ManyToOne(optional = false)
    private Rolprovider rolProviderId;
    @JoinColumn(name = "providerId", referencedColumnName = "providerId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Provider provider;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userprovider")
    private Collection<Accessprovider> accessproviderCollection;

    public Userprovider() {
    }

    public Userprovider(UserproviderPK userproviderPK) {
        this.userproviderPK = userproviderPK;
    }

    public Userprovider(UserproviderPK userproviderPK, String name, String lastName, String ci, char genero, String phone, String email, String login, String password, boolean active) {
        this.userproviderPK = userproviderPK;
        this.name = name;
        this.lastName = lastName;
        this.ci = ci;
        this.genero = genero;
        this.phone = phone;
        this.email = email;
        this.login = login;
        this.password = password;
        this.active = active;
    }

    public Userprovider(int providerId, int userProviderId) {
        this.userproviderPK = new UserproviderPK(providerId, userProviderId);
    }

    public UserproviderPK getUserproviderPK() {
        return userproviderPK;
    }

    public void setUserproviderPK(UserproviderPK userproviderPK) {
        this.userproviderPK = userproviderPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLastName2() {
        return lastName2;
    }

    public void setLastName2(String lastName2) {
        this.lastName2 = lastName2;
    }

    public String getCi() {
        return ci;
    }

    public void setCi(String ci) {
        this.ci = ci;
    }

    public char getGenero() {
        return genero;
    }

    public void setGenero(char genero) {
        this.genero = genero;
    }

    public String getCellphone() {
        return cellphone;
    }

    public void setCellphone(String cellphone) {
        this.cellphone = cellphone;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail2() {
        return email2;
    }

    public void setEmail2(String email2) {
        this.email2 = email2;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Date getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @XmlTransient
    public Collection<Package> getPackageCollection() {
        return packageCollection;
    }

    public void setPackageCollection(Collection<Package> packageCollection) {
        this.packageCollection = packageCollection;
    }

    public Rolprovider getRolProviderId() {
        return rolProviderId;
    }

    public void setRolProviderId(Rolprovider rolProviderId) {
        this.rolProviderId = rolProviderId;
    }

    public Provider getProvider() {
        return provider;
    }

    public void setProvider(Provider provider) {
        this.provider = provider;
    }

    @XmlTransient
    public Collection<Accessprovider> getAccessproviderCollection() {
        return accessproviderCollection;
    }

    public void setAccessproviderCollection(Collection<Accessprovider> accessproviderCollection) {
        this.accessproviderCollection = accessproviderCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userproviderPK != null ? userproviderPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Userprovider)) {
            return false;
        }
        Userprovider other = (Userprovider) object;
        if ((this.userproviderPK == null && other.userproviderPK != null) || (this.userproviderPK != null && !this.userproviderPK.equals(other.userproviderPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Userprovider[ userproviderPK=" + userproviderPK + " ]";
    }
    
}
